package com.oa.android.adapter;

import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.oa.android.R;
import com.oa.android.activity.CgxActivity;
import com.oa.android.entry.Emil;

import java.util.List;

/**
 * 邮件适配器
 * Created by zouqh on 2016/6/12.
 */
public class EmilAdapter extends BaseAdapter {
    private Context context;
    private List<Emil> emils;
    private int type;//1:收件箱  2：发件箱、草稿箱

    public EmilAdapter (Context context, List<Emil> list,int types){
        this.context=context;
        this.emils=list;
        type=types;
    }
    @Override
    public int getCount() {
        return emils.size();
    }

    @Override
    public Object getItem(int position) {
        return emils.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHodler viewHodler;
        if (convertView==null){
            viewHodler=new ViewHodler();
            convertView= LayoutInflater.from(context).inflate(R.layout.emil_item,null);
            viewHodler.form=(TextView)convertView.findViewById(R.id.form);
            viewHodler.time=(TextView)convertView.findViewById(R.id.time);
            viewHodler.icon=(ImageView)convertView.findViewById(R.id.icon) ;
            viewHodler.emilTitle=(TextView)convertView.findViewById(R.id.emilTitle);
            viewHodler.emilContent=(TextView)convertView.findViewById(R.id.emilContent);
            viewHodler.form=(TextView)convertView.findViewById(R.id.form);
            convertView.setTag(viewHodler);
        }else {
            viewHodler= (ViewHodler) convertView.getTag();
        }
        Emil emil=emils.get(position);
        if (type==1){
            if (emil.getZTNAME().equals("未读")){
                viewHodler.icon.setVisibility(View.VISIBLE);
            }else{
                viewHodler.icon.setVisibility(View.GONE);
            }

            viewHodler.form.setText(emil.getEMPNAME()+"");
        }else{
            viewHodler.icon.setVisibility(View.GONE);
            viewHodler.form.setText(emil.getEMPNAMES()+"");
//            CgxActivity.activity.getjsPerson(viewHodler.form,emil.getID());
        }

        viewHodler.time.setText(emil.getOPTIME()+"");
        viewHodler.emilTitle.setText(emil.getTITLE()+"");
        viewHodler.emilContent.setText(Html.fromHtml(emil.getCONTENT())+"");

        return convertView;
    }

    class ViewHodler{
        TextView form;
        TextView time;
        TextView emilTitle;
        TextView emilContent;
        ImageView icon;
    }
}
